<template>
  <div class="app-container">
    <el-card class="card-form">
      <div class="my-project-title">我的项目</div>
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="项目名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入"
            clearable
            size="small"
            style="width: 252px"
          />
        </el-form-item>
        <el-form-item label="项目类别" prop="type">
          <el-select
            v-model="queryParams.type"
            placeholder="请选择"
            clearable
            size="small"
            style="width: 252px"
          >
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="项目性质" prop="nature">
          <el-select
            v-model="queryParams.nature"
            placeholder="请选择"
            clearable
            size="small"
            style="width: 252px"
          >
            <el-option
              v-for="dict in natureOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="handleQuery"
            >查询</el-button
          >
          <el-button size="small" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="card-table">
      <div style="position: absolute;right:20px;top:30px;z-index: 99;" @click="handleApplication"><el-button type="primary" size="small">项目申报</el-button></div>            
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="全部" name="first">
        </el-tab-pane>
        <el-tab-pane  name="second">
          <span slot="label"><el-badge :value="projectCount.apply" class="item" type="primary">项目申报</el-badge></span>
        </el-tab-pane>
        <el-tab-pane  name="third">
          <span slot="label"><el-badge :value="projectCount.schemeDeclaration" class="item" type="primary">方案申报</el-badge></span>
        </el-tab-pane>
        <el-tab-pane  name="fourth">
          <span slot="label"><el-badge :value="projectCount.implement" class="item" type="primary">项目实施</el-badge></span>
        </el-tab-pane>
        <el-tab-pane  name="five">
          <span slot="label"><el-badge :value="projectCount.check" class="item" type="primary">项目验收</el-badge></span>
        </el-tab-pane>
      </el-tabs>
      <div class="button-box">
          <el-button size="small" :class="item.value === processingStatus ? 'active' : 'plain' " v-for="item in processingStatusMap" :key="item.value" @click="changeProcessingStatus(item)">{{item.label}} </el-button>
        </div>
      <TableData ref="tableDataComTwo" :isShow="isShow" :totalTo="total" :tableData="tableData" @getList="getList"></TableData>
      <el-pagination
        v-show="total > 0"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="queryParams.pageSize"
        :current-page="queryParams.pageNum"
        :page-sizes="[10, 20, 30, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
import {
  listMyManagement,
  getMyManagement,
  delNotice,
  addNotice,
  updateNotice,
  getStatusDicts,
  getAnnualPlan,
} from "@/api/projectCompany/myProject";
import {getProjectCount} from '@/api/manage/manage'
import TableData from "./components/tableData";
export default {
  name: "Expert",
  components: {
    TableData,
  },
  data() {
    const processingStatusMap  =  [
        ['all', '全部'],
        ['0', '待提交'],
        ['1', '待审批'],
        ['2', '已完成']
      ].map(([value,label]) => ({value,label}));
    return {
      // 遮罩层
      loading: false,
      // 是否显示项目阶段
      isShow: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        type: undefined,
        nature: undefined,
        isState: undefined,
        stag:undefined,
        statusCollect:[]
      },
      // 日期范围
      dateRange: [],
      // 项目类别字典
      typeOptions:[
        {dictValue:"0",dictLabel:"建设类（新开工）"},
        {dictValue:"1",dictLabel:"建设类（续建）"},
        {dictValue:"2",dictLabel:"购买服务类"},
        { dictValue: "3", dictLabel: "运维类" },
        { dictValue: "4", dictLabel: "其他" },],
      // 项目性质字典
      natureOptions:[{dictValue:"0",dictLabel:"年度项目"},{dictValue:"1",dictLabel:"增补项目"}],
      // 专家分类
      statusOptions: [{dictValue:"0",dictLabel:"已提交"},{dictValue:"1",dictLabel:"待审核"},{dictValue:"2",dictLabel:"通过"},{dictValue:"3",dictLabel:"退回修改"},{dictValue:"4",dictLabel:"驳回"}],
      // 被点击tabs标签
      activeName: "first",
      // 表格数据
      tableData: [],
      // 总条数
      total: 1,
      projectCount:{},//项目统计
      processingStatusMap,
      processingStatus: 'all',
    };
  },
  created() {
    this.getList()
    getStatusDicts().then(response=>{
      // console.log('获取状态',response);
      this.statusOptions = response.data.filter(item=>!(item.dictLabel=='三方审批'||item.dictLabel=='待考评'||item.dictLabel=='已考评'))
    })
    this.getProjectCountNum()
  },
  methods: {
    /** 查询我的项目管理列表 */
    getList() {
      this.loading = true;
      const processingStatusQuery = this.getProcessingStatusQuery()
      listMyManagement({
        ...this.queryParams,
        ...processingStatusQuery,
      }).then((response) => {
        this.tableData = response.list;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if(this.queryParams.stag==""||this.queryParams.stag==undefined){
        this.getList();
      }
      if(this.queryParams.stag==0){
        this.getList();

      }
      if(this.queryParams.stag==1){
        this.getList();

      }
      if(this.queryParams.stag==2){
        this.getList();

      }
      if(this.queryParams.stag==3){
        this.getList();

      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 项目申报按钮操作
    handleApplication(){
      getAnnualPlan().then(response=>{
        if(response.annualProjectPlan==null){
          this.$router.push({
            path: "/projectCompany/supplementaryDeclaration",
            query: { planId: '' },
          });
        }else{
          this.$router.push({
            path: "/projectCompany/annualReturn",
            query: { planId: response.annualProjectPlan.planId,planName: response.annualProjectPlan.name },
          });
        }
      })
    },
    /** 点击tabs标签 */
    handleClick(tab, event) {
      if (tab.index == "0") {
        this.isShow = true;
        this.queryParams.stag = ""
        this.getList();

      }
      if (tab.index == "1") {
        this.isShow = false;
        this.queryParams.stag = 0
        this.getList();

      }
      if (tab.index == "2") {
        this.isShow = false;
        this.queryParams.stag = 1
        this.getList();

      }
      if (tab.index == "3") {
        this.isShow = false;
        this.queryParams.stag = 2
        this.getList();

      }
      if (tab.index == "4") {
        this.isShow = false;
        this.queryParams.stag = 3
        this.getList();

      }
    },
    /** 分页 */
    handleSizeChange(val) {
      this.queryParams.pageSize=val
      this.queryParams.pageNum = 1;
      this.getList()
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum=val
      this.getList()
    },
    //获取项目数量统计
    getProjectCountNum(){
      getProjectCount().then(res =>{
        this.projectCount=res
        console.log(res)
      })
    },
    getProcessingStatusQuery() {
      return {
        processingStatus : this.processingStatus === 'all' ? undefined : this.processingStatus,
        statusCollect: this.processingStatus === 'all' ? undefined : [''],
      };
    },
    changeProcessingStatus(data) {
      if (!data || this.projectStatus === data.value) return;
      this.processingStatus = data.value
      this.queryParams.pageNum = 1;
      this.getList();
    }
  },
};
</script>
<style scoped lang="scss">
.my-project-title {
  font-size: 18px;
  font-family: PingFang SC, PingFang SC-Medium;
  font-weight: 500;
  margin-bottom: 24px;
  color: #000000;
}
.card-table {
  margin-top: 10px;
  .el-pagination {
    text-align: center;
    margin-top: 40px;
  }
}
</style>
<style lang="scss">
.card-form {
  .el-card__body {
    padding-bottom: 0;
  }
  label {
    font-weight: normal !important;
  }
  .el-form--inline .el-form-item {
    margin-right: 60px;
  }
}
.card-table {
  position: relative;
  // tabs标签页样式更改
  .el-tabs__header {
    margin: 0px 0px 24px;
  }
  .el-tabs__nav-wrap {
    border-bottom: 1px solid #EBECEF;
  }
  .el-tabs__nav-wrap::after {
    position: static !important;
  }
  .el-tabs__item {
    height: 64px;
    line-height: 64px;
    font-size: 16px;
    font-family: PingFang SC, PingFang SC-Medium;
    font-weight: 500;
    color: #000000;
  }
  .el-tabs__item.is-active {
    color: #000 !important;
  }
  .el-tabs__active-bar {
    color: #156fed !important;
    height: 4px;
  }
  /* 对tabs标签右上角标记样式修改 */
  .el-badge__content.is-fixed {
    position: absolute;
    top: 20px;
    right: 5px;
  }
}
.button-box{
  height: 48px;
}
.el-button {
  &.plain{
    background: #ffffff;
      border: 1px solid #3171ee;
      border-radius: 4px;
      color: #3171ee;
  }
  &.active{
    color: #fff;
    background-color: #3171ee;
  }
}
</style>
